package com.zhangtingshu.service.impl;

import com.zhangtingshu.dao.UserDao;
import com.zhangtingshu.pojo.User;
import com.zhangtingshu.service.UserService;
import com.zhangtingshu.util.MD5Util;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.UUID;

/**
 * @author zhangtingshu
 * 用户业务逻辑实现类
 */
@Service
public class UserServiceImpl implements UserService {

    Logger logger = Logger.getLogger(UserServiceImpl.class);

    @Autowired
    private UserDao userDao;

    @Override
    public int saveUser(User user) {
        user.setUuid(UUID.randomUUID().toString());
        String pass = MD5Util.md5(user.getPass());
        user.setPass(pass);
        userDao.saveUser(user);
        logger.info(user.getUid());
        return user.getUid();
    }

    @Override
    public User findByPassAndId(User user) {
        user.setPass(MD5Util.md5(user.getPass()));
        return userDao.findByPassAndId(user);
    }

    @Override
    public User findById(String uuid) {
        return userDao.findById(uuid);
    }

    @Override
    public List<User> findAll() {
        return userDao.findAll();
    }

    @Override
    public boolean delete(int id) {
        return userDao.delete(id) > 0 ? true : false;
    }
}
